//1、分页模糊匹配查询接口
function pageSelectApi(data) {
    return $.ajax({
        // http://localhost:8080
        url: "/user/pageSelect",
        method: 'POST',
        contentType: 'application/json;charset=UTF-8',
        dataType: 'json',
        // async:false,
        data: JSON.stringify(data)
    })
}

//2、拿到后台给生成的账号
function getUsernameApi() {
    return $.ajax({
        // http://localhost:8080
        url: "/user/getUsername",
        method: 'get',
        async:false
    })
}
//3、添加的请求发送
function addUserApi(data){
    return $.ajax({
        // http://localhost:8080
        url: "/user/register",
        method: 'POST',
        contentType: 'application/json;charset=UTF-8',
        dataType: 'json',
        data: JSON.stringify(data)});
}
//4、修改操作
function updateUserApi(data){
    return $.ajax({
        // http://localhost:8080
        url: "/user/updateUser",
        method: 'POST',
        contentType: 'application/json;charset=UTF-8',
        dataType: 'json',
        data: JSON.stringify(data)});
}

//5、添加表单验证
function formValidation(data,type){
    var flag=true;
    if(!(/^.{1,10}$/.test(data.nickname))){
        //不符合提示信息,清空对应的输入框
        alert("昵称格式不规范")
        data.nickname="";
        return false;
    }else if(!(/^[a-zA-Z0-9]{6,8}$/.test(data.password))){
        alert("密码格式不规范:请输入6-8位的数字字母组合的密码")
        data.password="";
        return false;
    }else if( "update" !== type && !(/^[1][3,4,5,7,8][0-9]{9}$/.test(data.phone))){
        alert("电话格式不规范:请输入11位的电话")
        data.phone="";
        return false;
    }else if(!(/^[1-9][0-9]{4,10}@qq.com$/.test(data.email))){
        alert("qq邮箱格式不正确")
        data.email="";
        return false;
    }
    return flag;
}

//7,根据id删除用户
function deleteUser(data) {
    return $.ajax({
        // http://localhost:8080
        url: "/user/deleteUser/"+data,
        method: 'get',
    })
}